package service

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto/rpc"
	"api-gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddFavorite(c *gin.Context) {
	var form request.AddFavorite
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	video, err := config.VideoRpcClient.AddFavorite(c, &__.AddFavoriteReq{
		UserId:  int64(form.UserId),
		VideoId: int64(form.VideoId),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "收藏完成", "data": gin.H{
		"favoriteId": video.FavoriteId,
	}})
	return
}
